﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace StringsFormatting
{
    class Program
    {
        static void EncodeFileTo64(TextReader input, TextWriter output)
        {
            if (input == null)
            {
                throw new ArgumentNullException("Input cannot be null!");
            }
            if (output == null)
            {
                throw new ArgumentNullException("Output cannot be null!");
            }
            string fileContent = input.ReadToEnd();
            byte[] toEncodeAsBytes = ASCIIEncoding.ASCII.GetBytes(fileContent);
            string encodedAsString = System.Convert.ToBase64String(toEncodeAsBytes);
            int i = 0;
            while (i < encodedAsString.Length)
            {
                output.WriteLine(encodedAsString.Substring(i, Math.Min(40, encodedAsString.Length - i)));
                i+=40;
            }
        }

        static void Main(string[] args)
        {
            using (StreamReader input = new StreamReader("notepad.exe"))
            {
                using(StreamWriter output = new StreamWriter("output.txt"))
                {
                    EncodeFileTo64(input, output);
                }
            }

        }
    }
}
